<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="90px"
    >
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="请输入关键字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="辨识结果" prop="resultCode">
        <el-select
          v-model="queryParams.resultCode"
          placeholder="请选择辨识结果"
          clearable
          @change="handleQuery"
        >
          <el-option label="成功" :value="1"></el-option>
          <el-option label="失败" :value="2"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="调用时间" prop="createTime">
        <el-date-picker
          v-model="createTime"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          :default-time="['00:00:00', '23:59:59']"
          @change="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userList">
      <el-table-column
        label="姓名"
        align="center"
        prop="patientName"
        width="100"
      />
      <el-table-column
        label="电话"
        align="center"
        prop="patientPhone"
        width="150"
      />
      <el-table-column label="性别" align="center" prop="patientSex" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.patientSex" />
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="patientAge" width="80" />
      <el-table-column label="照片类型" align="center" prop="imageType" width="80">
        <template slot-scope="scope">
          <div>{{ scope.row.imageType === 1 ? '舌相' : '面相' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="照片" align="center" prop="imageUrl" width="100">
        <template slot-scope="scope">
          <image-preview
            v-if="scope.row.imageUrl"
            :src="scope.row.imageUrl"
            :width="50"
            :height="50"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="调用时间"
        align="center"
        prop="requestTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requestTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="辨识结果"
        align="center"
        prop="resultCode"
        min-width="150"
      >
        <template slot-scope="{ row }">
          <div v-if="row.resultCode === 1">成功</div>
          <div v-if="row.resultCode === 2">失败 <div v-if="row.resultMessage" class="colorRED pl-5 fz-12">({{row.resultMessage}})</div></div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120px" fixed="right">
        <template slot-scope="{ row }">
           <el-button size="mini" type="text" icon="el-icon-document" @click="openDetails(row)">
            查看详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <TongueDetail ref="TongueDetail" />
  </div>
</template>

<script>
import { tonguefaceList } from '@/api/user/tongue.js'
import TongueDetail from './tongueDetail'
import { getPickerShortcuts } from '@/utils'

export default {
  name: "Tongue",
  dicts: ["sys_user_sex"],
  components: {
    TongueDetail
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 查询参数
      pickerOptions: {
        shortcuts: getPickerShortcuts()
      },
      // 用户表格数据
      userList: [],
      createTime: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: null,
        resultCode: null,
        requestTimegt: null,
        requestTimelt: null,
      },
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.queryParams.requestTimegt = this.createTime && this.createTime.length ? this.createTime[0] : "";
      this.queryParams.requestTimelt = this.createTime && this.createTime.length ? this.createTime[1] : "";
      this.loading = true;
      tonguefaceList(this.queryParams).then((response) => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.createTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 打开详情弹窗
    openDetails(row) {
      this.$refs.TongueDetail.openModal(row);
    },
  },
};
</script>
